package com.py.credit.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.dao.YzApiDateDao;
import com.py.credit.service.YzApiDateService;
import com.py.credit.utils.getEnterpriseDataUtil;

@Service
public class YzApiDateServiceImpl implements YzApiDateService{
	@Autowired
	private YzApiDateDao yzApiDateDao;
	//企业裁判文书
	private static String QYXPWSA="/services/query/enterprise/law/entCpwsInfomation";
	//企业执行公告信息
	private static String QYZXGGB="/services/query/enterprise/law/entZxggInfomation";
	//企业失信信息
	private static String QYSXXXC="/services/query/enterprise/law/entShixinInfomation";
	//企业开庭信息
	private static String QYKTXXD="/services/query/enterprise/law/entKtggInfomation";
	//企业法院公告信息
	private static String QYFYGGE="/services/query/enterprise/law/entFyggInfomation";
	//企业网贷黑名单
	private static String QYWDHF="/services/query/enterprise/law/entWdhmdInfomation";
	//企业案件流程信息
	private static String QYAJLCG="/services/query/enterprise/law/entAjlcInfomation";
	//企业曝光台信息
	private static String QYBGTH="/services/query/enterprise/law/entBgtInfomation";
	//企业注册信息
	private static String QYBISI="/services/query/enterprise/basic/entBasic";
	//企业股东及出资信息
	private static String QYSHJ="/services/query/enterprise/basic/entShareHolder";
	//企业主要管理人员信息
	private static String QYPERSONK="/services/query/enterprise/basic/entPerson";
	//企业法定代表人对外投资信息
	private static String QYFRINVL="/services/query/enterprise/basic/entFrinv";
	//企业法定代表人其他公司任职信息
	private static String QYFRPOSITIONM="/services/query/enterprise/basic/entFrposition";
	//企业对外投资信息
	private static String QYENTINVN="/services/query/enterprise/basic/entEntinv";
	//企业信息变更
	private static String QYALTERO="/services/query/enterprise/basic/entAlter";


	@Override
	public void insertBeijingDate(String entNameOrEntCode) {
		String entName="entNameOrEntCode";
		String date=null;
		List<Map<String,Object>> dataList=new  ArrayList<Map<String,Object>>();
		try {
			date=getEnterpriseDataUtil.getEntInfo(QYXPWSA, entName, entNameOrEntCode,null);
			dataList=this.JsonToListMap(date,entNameOrEntCode);
			yzApiDateDao.insertQYXPWSA(dataList);
		} catch (Exception e) {
			 ExceptionLogger.error("新增企业宣判文书", e.getMessage(), e);
			e.printStackTrace();
		}
	}
	


	@Override
	public void insertQYZXGGB(String entNameOrEntCode) {
		String entName="entNameOrEntCode";
		String date=null;
		List<Map<String,Object>> dataList=new  ArrayList<Map<String,Object>>();
		try {
			date=getEnterpriseDataUtil.getEntInfo(QYZXGGB, entName, entNameOrEntCode,null);
			dataList=this.JsonToListMap(date,entNameOrEntCode);
			yzApiDateDao.insertQYZXGGB(dataList);
		} catch (Exception e) {
			 ExceptionLogger.error("新增企业执行公告信息", e.getMessage(), e);
			e.printStackTrace();
		}
		
	}
	
	
	public List<Map<String,Object>> JsonToListMap(String date,String entNameOrEntCode){
		 JSONObject mapTypes = JSON.parseObject(date);
		 JSONArray mapdate=(JSONArray) mapTypes.get("data");
		 List<Map<String,Object>> dataList=new  ArrayList<Map<String,Object>>();
		 if(mapdate.size()>0){
			  for(int i=0;i<mapdate.size();i++){
				  Map<String,Object> dataMap=new HashMap<String,Object>();
				  dataMap.put("A000001", entNameOrEntCode);
				  JSONObject job = mapdate.getJSONObject(i); 
				  for (Map.Entry<String, Object> entry : job.entrySet()) {
					  String key=entry.getKey();
					  String value=null;
					  if(!entry.getValue().getClass().equals(JSONArray.class)) {
						  value=(String) entry.getValue();
						  dataMap.put(key,value);
					  }
					  
			        }
				  dataList.add(dataMap);
				 }
			}
		 return dataList;
	}
	
}
